#include "gui.h"
#include "GWindow.h"

#include "platform.h"

//////////////////////////////////////////////////////////////////////////


GWindow::GWindow(GForm* parent)
:GForm(parent)
,m_pCenterForm(0)
{
    GHForm hForm = createWindow(WINDOW, this);
    
    if (GForm::s_pMainForm == 0)
        GForm::s_pMainForm = this;
}

GWindow::~GWindow()
{

}

void GWindow::setCenterForm(GForm* pForm)
{
	if (pForm == this)
		return;
	m_pCenterForm = pForm; 
	GRect rc = getClientRect();
	m_pCenterForm->resize(GSize(rc.width(), rc.height()));
	m_pCenterForm->setFocus();
    m_pCenterForm->show();
}

//////////////////////////////////////////////////////////////////////////

void GWindow::createEvent()
{
	GMenu mFile;
	mFile.addSeparator();
	mFile.addItem(ID_MENU_EXIT, GTEXT("&Exit\tCtrl+X"));
	mFile.setTitle(GTEXT("&File"));
    bool b = m_hMainMenu.addMenu(mFile);
	m_hMainMenu.addItem(ID_MENU_HELP, GTEXT("&Help"));
	setWindowMenu(this, m_hMainMenu);  // set menu operation have to be done after menu's creation!
}

void GWindow::sizeEvent( GSizeEvent& event )
{
	if (m_pCenterForm != NULL)
	{
		GRect rc = getClientRect();
		m_pCenterForm->resize(GSize(rc.width(), rc.height()));
	}
}

void GWindow::itemEvent(int itemID, long param)
{
    if (itemID == ID_MENU_EXIT)
    {
        close();
        return ;
    }
}

void GWindow::closeEvent()
{
    destroyWindow(getHandle());
}